<?php

/**
 * 
 * @author 陈德本
 *
 */
class btsyncController extends Controller
{

    public $initphp_list = array(
        'content'
    );

    private $conf;

    public function run()
    {
        set_time_limit(0);
        for ($i = 0; $i < 900; $i = $i + 10) {
            $url = "http://btsynckeys.com/" . $i;
            $data = file_get_contents($url);
            $pat = "#<td>(.*)</td>#";
            preg_match_all($pat, $data, $arr);
            $names = $key = array();
            foreach ($arr[1] as $k => $v) {
                if ($k % 4 == 0) {
                    $names[] = $v;
                }
                if ($k % 4 == 1) {
                    $key[] = $v;
                }
            }
            $data = array_combine($key, $names);
            foreach ($data as $k => $v) {
                $temp = array();
                $temp['key'] = $k;
                $temp['names'] = $v;
                try {
                    $this->getDao()->add($temp);
                }catch (Exception $e){
                    echo $e->getCode().":".$e->getMessage();
                    echo "<br>";
                }
            }
        }
        echo "OK!";
    }

    /**
     *
     * @return syncDao
     */
    private function getDao()
    {
        return InitPHP::getDao("sync");
    }
}